﻿using PhotoKiosk.ViewModel.Helpers;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;

namespace PhotoKiosk.ViewModel
{
    public class FinishOrderViewModel : ViewModelBase
    {
        private MainWindowViewModel m_mainWindowViewModel;
        private DelegateCommand m_startNewCommand;
        private Task m_task;

        public FinishOrderViewModel(MainWindowViewModel i_mainWindowViewModel)
        {
            this.m_mainWindowViewModel = i_mainWindowViewModel;

            m_task = Task.Factory.StartNew(() =>
            {
                Thread.Sleep(10000);
                this.startNewCommandExecute();
            });
        }

        public int OrderId
        {
            get
            {
                return m_mainWindowViewModel.SystemData.Order.IDNumber;
            }
        }

        public ICommand StartNewCommand
        {
            get
            {
                if (m_startNewCommand == null)
                {
                    m_startNewCommand = new DelegateCommand(param => this.startNewCommandExecute(), param => this.startNewCommandCanExecute());
                }
                return m_startNewCommand;
            }
        }

        private bool startNewCommandCanExecute()
        {
            return true;
        }

        private void startNewCommandExecute()
        {
            m_mainWindowViewModel.CurrentViewModel = new SelectSourceViewModel(m_mainWindowViewModel);
        }
    }
}
